<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

//Route::middleware('refresh.token')->group(function($router) {
//    $router->get('profile','UserController@profile');
//});


Route::group(['middleware'=>['cross']],function() {

    //版本
    Route::post('versionUpdate','Api\VersionController@versionUpdate');
    Route::any('getDownloadUrl','Api\VersionController@getDownloadUrl');

    //用户注册/登陆
    Route::post('register', 'LoginController@register');
    Route::post('login', 'LoginController@login')->name('login');;
    Route::post('retrievePassword', 'LoginController@retrievePassword');

    //需要验证token
    Route::group(['middleware' => ['auth:api']], function () {
        //退出登陆
        Route::post('logout', 'LoginController@logout');
        Route::post('resetPassword', 'LoginController@resetPassword');
        //user
        Route::group(['prefix' => 'user'],function() {
            Route::post('userInfo', 'Api\UsersController@userInfo');
            //书架
            Route::post('addBookShelf', 'Api\BookShelfController@addBookShelf');
            Route::post('delBookShelf', 'Api\BookShelfController@delBookShelf');
            Route::post('saveBookShelf', 'Api\BookShelfController@saveBookShelf');
            Route::post('bookShelfList', 'Api\BookShelfController@bookShelfList');
        });
    });

    //common
    Route::group(['prefix' => 'common'],function() {
        Route::post('getBookType', 'Api\CommonController@getBookType');
        Route::post('sendMailCode', 'Api\CommonController@sendMailCode');
        Route::post('checkMailCode', 'Api\CommonController@checkMailCode');
    });

    //books
    Route::group(['prefix' => 'books'], function() {
        //首页
        Route::post('index', 'Api\IndexController@index');
        Route::post('updateList', 'Api\IndexController@updateList');
        Route::post('overList', 'Api\IndexController@overList');
        Route::post('typeList', 'Api\IndexController@typeList');
        Route::post('clickList', 'Api\IndexController@clickList');
        Route::post('bannerList', 'Api\IndexController@bannerList');
        //分类页  and 章节列表 and 搜索
        Route::post('bookList', 'Api\ListController@bookList');
        Route::post('chapterList', 'Api\ListController@chapterList');
        Route::post('chapterAllList', 'Api\ListController@chapterAllList');
        Route::post('search', 'Api\ListController@search');
        //详情页 and 阅读页
        Route::post('detail', 'Api\BooksController@detail');
        Route::post('readContent', 'Api\BooksController@readContent');
    });

    //old
    Route::group(['prefix' => 'old'],function() {
        //首页
        Route::post('index', 'Api\OldController@index');
        Route::post('detail', 'Api\OldController@detail');
        Route::post('bookContent', 'Api\OldController@bookContent');

        Route::post('chapterList', 'Api\OldController@chapterList');

        Route::post('bookList', 'Api\OldController@bookList');
        Route::post('search', 'Api\OldController@search');
    });

    //test
    Route::post('test','Api\TestController@test');

});

